package com.zm.demo.core.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Set;

/**
 * @author z01140
 * @Package: com.zm.demo.core.redis
 * @Description:
 * @CreateDate 2022/2/22 16:06
 * @UpdateDate 2022/2/22 16:06
 */
public class SentinelClient {


    public static void main(String[] args) {

        Set<String> sentinels = new HashSet<String>();
        String hostAndPort1 = "192.168.26.223:26377,192.168.26.223:26378,192.168.26.223:26379";
        for (String s : hostAndPort1.split(",")) {
            sentinels.add(s);
        }
        String clusterName = "mymaster";
        String password = "Passwd@4321";
        JedisSentinelPool redisSentinelJedisPool = new JedisSentinelPool(clusterName,sentinels,password);
        Jedis jedis = null;
        jedis = redisSentinelJedisPool.getResource();
        System.out.println(jedis.ping());
        jedis.setex("zmtest", 100, "zmtest");
        System.out.println(jedis.get("zmtest"));
        jedis.close();
    }
}
